n = input()
a = []
s = []
c = []
for i in n:
    a.append(i)
if len(a) == 4 and n.isdigit():
    n1 = int(a[0] + a[1] + a[2] + a[3])
    n2 = int(a[0] + a[1] + a[2])
    n3 = int(a[1] + a[2] + a[3])
    n4 = int(a[0] + a[1])
    n5 = int(a[1] + a[2])
    n6 = int(a[2] + a[3])
    n7 = int(a[0])
    n8 = int(a[1])
    n9 = int(a[2])
    n10 = int(a[3])
    s.append(n1)
    s.append(n2)
    s.append(n3)
    s.append(n4)
    s.append(n5)
    s.append(n6)
    s.append(n7)
    s.append(n8)
    s.append(n9)
    s.append(n10)
    for i in s:
        k = 0
        for ii in range(2, int(i)):
            if int(i) % ii == 0:
                k = 1
                break
        if k == 0:
            c.append(i)
    if len(c) == 0:
        print(0)
    else:
        print(max(c))
else:
    print(0)
